package com.shangyueshang.utils;

import cn.hutool.http.HttpUtil;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.TimerTask;

/**
 * @author JokeyFeng
 * @date: 2024/5/3 22:10
 * @project: shangyueshang
 * @package: com.shangyueshang.utils
 * @comment:
 */
public class PushPlusUtil {
	
	/**
	 * push推送
	 *
	 * @param token    token
	 * @param title    消息标题
	 * @param content  具体消息内容
	 * @param template 发送消息模板
	 */
	public static TimerTask sendNotice(String token, String title, String content, String template) {
		return new TimerTask() {
			@Override
			public void run() {
				String url = "http://www.pushplus.plus/send";
				Map<String, Object> map = new HashMap<>(4);
				map.put("token", token);
				map.put("title", title);
				map.put("content", content);
				if (!StringUtils.hasText(template)) {
					map.put("template", "html");
				}
				HttpUtil.post(url, map);
			}
		};
	}
}
